import os
import django

# 设置Django环境
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ai_teach.settings')
django.setup()

from django.db import connection

def get_table_info():
    """获取表结构信息"""
    with connection.cursor() as cursor:
        # 检查表是否存在
        cursor.execute("""
            SELECT COUNT(*) 
            FROM information_schema.tables 
            WHERE table_schema = DATABASE() 
            AND table_name = 'student_study_plan'
        """)
        table_exists = cursor.fetchone()[0]
        
        if not table_exists:
            print("表student_study_plan不存在")
            return
        
        # 获取表结构
        print("student_study_plan表结构:")
        cursor.execute("DESCRIBE student_study_plan")
        columns = cursor.fetchall()
        for col in columns:
            print(f"  {col[0]}: {col[1]} ({col[2]}) {col[3]}")
        
        # 检查是否有数据
        cursor.execute("SELECT COUNT(*) FROM student_study_plan")
        count = cursor.fetchone()[0]
        print(f"\n表中共有 {count} 条记录")
        
        if count > 0:
            # 查看一条示例数据
            cursor.execute("SELECT * FROM student_study_plan LIMIT 1")
            sample_row = cursor.fetchone()
            column_names = [col[0] for col in cursor.description]
            print("\n示例数据:")
            for i, val in enumerate(sample_row):
                print(f"  {column_names[i]}: {val}")

if __name__ == "__main__":
    get_table_info() 